"""
演示Python pymysql库的基础操作
"""
from pymysql import Connection
# 构建到MySQL数据库的链接
conn = Connection(
    host="localhost",
    port=3306,
    user="root",
    passwd="hzh3589153651",
)
# print(conn.get_server_info())

# 执行非查询性质SQL
cursor = conn.cursor() # 获取游标对象
# 选择数据库
# conn.select_db("test")
conn.select_db("world")
# 执行sql语句
cursor.execute("create table test_pymysql(id int);")
cursor.execute("create table test_pymysql2(id int)")
cursor.execute("select * from student")
result = cursor.fetchall()
for r in result:
    print(r)
# 关闭链接
conn.close()
